<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理网页</title>
    <!--引入vue.js库-->
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
    <script src="/js/vue.js"></script>
    <!-- element-ui引入样式 展示数据的-->
    <link rel="stylesheet" href="/css/index.css">
    <!-- element-ui引入组件库 -->
    <script src="/js/index.js"></script>
    <!--引入axios库  从后端获取数据-->
    <!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
    <script src="/js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <el-row style="margin-top: 30px;">
            <el-col :span="4">
                <div class="grid-content bg-purple">
                    <el-input v-model="searchForm.name" placeholder="请输入门票名称"></el-input>
                </div>
            </el-col>
            <el-col :span="0.5">
                <div class="grid-content bg-purple-light">
                    &nbsp;&nbsp;&nbsp;
                </div>
            </el-col>
            <el-col :span="4">
                <div class="grid-content bg-purple-light">
                    <el-input v-model="searchForm.oprice" placeholder="请输入门价"></el-input>
                </div>
            </el-col>
            <el-col :span="0.5">
                <div class="grid-content bg-purple-light">
                    &nbsp;&nbsp;&nbsp;
                </div>
            </el-col>
            <el-col :span="14">
                <div class="grid-content bg-purple">
                    <el-button type="primary" @click="search" >搜索</el-button>
                </div>
            </el-col>
            <el-col :span="1">
                <div class="grid-content bg-purple">
                    <el-button type="primary" @click="add() ">添加</el-button>
                </div>
            </el-col>
        </el-row>

    <el-table
            :data="tableData"
            style="width: 100%;margin-top: 20px;"
            :row-class-name="tableRowClassName">
        <el-table-column
                prop="scenicid"
                label="景区id">
        </el-table-column>
        <el-table-column
                prop="name"
                label="门票名称">
        </el-table-column>
        <el-table-column
                prop="oprice"
                label="门市价">
        </el-table-column>
        <el-table-column
                prop="fkqx"
                label="乐乐价">
        </el-table-column>
        <el-table-column
                prop="maxdaysell"
                label="支付方式">
        </el-table-column>
        <el-table-column
                prop="maxdaypersonsell"
                label="付款期限">
        </el-table-column>
        <el-table-column
                prop="isclient"
                label="每日更新">
        </el-table-column>
        <el-table-column
                prop="dpj"
                label="须知">
        </el-table-column>
        <el-table-column
                prop="bgtime"
                label="门票类型">
        </el-table-column>
        <el-table-column
                prop="shtime"
                label="取票方式">
        </el-table-column>


        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index, scope.row)">修改
                </el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除
                </el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination
            style="width: 100%;margin-top: 20px;"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage4"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
<!--    添加-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="门票id" :label-width="formLabelWidth">
                <el-input v-model="form.id" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="门票名称" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="门市价" :label-width="formLabelWidth">
                <el-input v-model="form.oprice" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="结束日期" :label-width="formLabelWidth">
                <el-input v-model="form.dprice" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="支付方式" :label-width="formLabelWidth">
                <el-input v-model="form.ptype" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="预售时限" :label-width="formLabelWidth">
                <el-input v-model="form.shstate" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addUser()">确 定</el-button>
        </div>
    </el-dialog>
</div>
<script>
    let vue = new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                pageSize: 5,
                total: 100,
                searchForm: {},
                dialogFormVisible: false,
                title: "添加",
                form: {},
                formLabelWidth: '120px',
            }
        },
        created: function () {//页面初始化时,需要执行的业务可以放入该方法

            this.loadData();
        },
        methods: {//存放所有使用的方法
            loadData() {
                let _this = this;
                //使用axios向后台发请求
                axios.post('/scenicticket/page',
                    {
                        "pageNo": this.currentPage, "pageSize": this.pageSize,
                        "data": {"name":this.searchForm.name,"oprice":this.searchForm.oprice}
                    })
                    .then(function (response) {
                        if (response.data.code == 200) {
                            _this.tableData = response.data.data.list;
                            _this.total = response.data.data.total;
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize = val;
                this.loadData();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.currentPage = val;
                this.loadData();
            },
            //更新
            handleEdit(index, row) {
                console.log(index, row);
                this.dialogFormVisible = true;
                this.title = "更新";
                this.form = row;
            },
            //添加
            add() {
                this.dialogFormVisible = true;
                this.title = "添加";
                this.form = {};
            },
            //添加更新
            addUser() {
                let _this = this;
                let uri = "/scenicticket/add";
                if (this.title == "更新") {
                    uri = "/scenicticket/update"
                }
                //使用axios向后台发请求
                axios.post(uri,
                    this.form)
                    .then(function (response) {
                        if (response.data.code == 200) {
                            _this.$message({
                                message: '成功',
                                type: 'success'
                            });
                            _this.dialogFormVisible = false;
                            _this.loadData();
                        }
                    })
                    .catch(function (error) {
                        _this.$message.error('错误');
                    });
            },
            //删除
            handleDelete(index, row) {
                let _this = this
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.delete("/scenicticket/" + row.id)
                        .then(function (response) {
                            _this.loadData()
                        })
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //搜索方法
            search() {
                this.currentPage = 1;
                this.loadData();
            }
        }
    })
</script>
</body>
</html>